// 引入封装好的axios函数
import request from "@/utils/request";
import type {
  CommentsItemParams,
  DetailSongParams,
  DynamicItem,
  TrackAllList,
  TrackAllListParams,
  GetCommentParams,
  HotSongListParams,
  CommentItemParams,
} from "./model/songList/detailsSong";

// 枚举路径
enum Api {
  getDetailsSongUrl = "/playlist/detail",
  getDynamicUrl = "/playlist/detail/dynamic",
  getTrackAllUrl = "/playlist/track/all",
  getSongPlayCountUrl = "/playlist/update/playcount",
  getCommentUrl = "/comment/playlist",
  getHotSongUrl = "/related/playlist",
  postCommentUrl = "/comment",
}

/**
 * 1:获取对应id的歌单详情数据
 */
export const getDetailsSongApi = (id: number) => {
  return request.get<unknown, DetailSongParams>(Api.getDetailsSongUrl, {
    params: {
      id,
    },
  });
};

/**
 * 2:获取歌单评论详情
 */
export const getDynamicApi = (id: number) => {
  return request.get<unknown, DynamicItem>(Api.getDynamicUrl, {
    params: {
      id,
    },
  });
};

/**
 * 3:获取歌曲列表数据:必须参数id,可选参数我们用不着
 */
export const getTrackAllApi = (id: number, limit: number) => {
  return request.get<unknown, TrackAllListParams>(Api.getTrackAllUrl, {
    params: {
      id,
      limit,
    },
  });
};

/**
 * 4:获取当前歌曲播放数据
 */
export const getSongPlayCountApi = (id: number) => {
  return request.get<unknown, any>(Api.getSongPlayCountUrl, {
    params: {
      id,
    },
  });
};

/**
 * 5:获取当前歌单的评论数据
 */
export const getCommentApi = ({ id, limit, offset }: GetCommentParams) => {
  return request.get<unknown, CommentsItemParams>(Api.getCommentUrl, {
    params: {
      id,
      limit,
      offset,
    },
  });
};

/**
 * 6:获取热门歌单数据
 */
export const getHotSongListApi = (id: number) => {
  return request.get<unknown, HotSongListParams>(Api.getHotSongUrl, {
    params: {
      id,
    },
  });
};

/**
 * 7:发送请求,发送评论数据
 */
export const postAddComment = ({ t, type, id, content }: CommentItemParams) => {
  return request.post<unknown, null>(
    Api.postCommentUrl,
    {},
    {
      params: {
        t,
        type,
        id,
        content,
      },
    }
  );
};
